package com.kizuki.springcloud.service;

import com.kizuki.springcloud.pojo.Dept;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 服务降级
 */
@Component
public class DeptClientServiceFallBackFactory implements FallbackFactory {

    @Override
    public DeptClientService create(Throwable throwable) {
        return new DeptClientService(){

            @Override
            public boolean addDept(Dept dept) {
                return false;
            }

            @Override
            public List<Dept> queryDepts() {
                return null;
            }

            @Override
            public Dept queryDeptById(int id) {
                return new Dept()
                        .setDeptno(id)
                        .setDeptname("已开启服务降级")
                        .setDb_source("请稍后再试");
            }
        };
    }
}
